package com.jzo2o.customer.mapper;

import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.customer.model.domain.AddressBook;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地址薄 Mapper 接口
 * </p>
 *
 * @author itcast
 * @since 2023-07-06
 */
public interface AddressBookMapper extends BaseMapper<AddressBook> {
    @Select("select * from address_book where user_id = #{userId} and is_deleted = 0")
    List<AddressBookResDTO> getByUserId(Long userId);

    @Update("update address_book set is_default = #{flag} where id = #{id}")
    void setDefault(Integer flag, Long id);

    @Select("select * from address_book where user_id = #{userId} and is_default = 1 and is_deleted = 0")
    AddressBook getDefaultAddress();
}
